//
//  ViewController.m
//  JSON
//
//  Created by Justsoso on 16/3/25.
//  Copyright © 2016年 Justsoso. All rights reserved.
//

#import "ViewController.h"

#import "Video.h"

@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic,strong) NSMutableArray *list;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
//    NSString *urlStr = @"http://120.25.226.186:32812/video?type=JSON";
//    
//    NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlStr]];
//    
//    NSError *error;
//    NSDictionary *resiltDict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error];
//    NSLog(@"%@",resiltDict);
//    
//    
//    NSArray *videosArr = resiltDict[@"videos"];
//    self.list = [NSMutableArray array];
//    for (NSDictionary *dict in videosArr)
//    {
//        Video *v = [Video videoWithDict:dict];
//        [self.list addObject:v];
//    }
    
    
    // 1. 获取并解析无锡的天气信息
//    NSString *urlStr = @"http://www.weather.com.cn/adat/cityinfo/101190201.html";
//    
//    NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlStr]];
//    
//    NSError *error;
//    NSDictionary *resiltDict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error];
//    NSLog(@"%@",resiltDict);
    
    // 2.
//    NSString *urlStr = @"http://www.okcoin.cn/api/ticker.do";
//    
//    NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlStr]];
//    
//    NSError *error;
//    NSDictionary *resiltDict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error];
//    NSLog(@"%@",resiltDict);
    
    
    // 3.
    
    
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.list.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"Cell"];
    }
    
    Video *v = self.list[indexPath.row];
    cell.textLabel.text = v.name;
    cell.detailTextLabel.text = v.url;
    
    NSString *imageUrlStr = [@"http://120.25.226.186:32812/" stringByAppendingString:v.image];
    NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageUrlStr]];
    UIImage *image = [UIImage imageWithData:imageData];
    cell.imageView.image = image;
    
    return cell;
}

@end
